from django.db import models

# Create your models here.
# 用户
class Users(models.Model):
    # 用户名
    username = models.CharField(max_length=32)
    # 密码
    password = models.CharField(max_length=77)
    # 手机号
    phone = models.CharField(max_length=11)
    # 邮箱
    email = models.CharField(max_length=32,null=True)
    # 性别
    sex = models.CharField(max_length=1,choices=(('男','1'),('女','0')),null=True)
    # 年龄
    age = models.IntegerField(null=True)
    # 状态  0正常 1禁用
    status = models.IntegerField(default=0)
    # 注册时间
    addtime = models.DateTimeField(auto_now_add=True)
    # 头像
    pic_url = models.CharField(max_length=100,null=True)



# 商品分类管理
class Cates(models.Model):

    # 类名
    name = models.CharField(max_length=32)
    # 父级
    pid = models.IntegerField()
    # 上级明细
    path= models.CharField(max_length=20)
    # 状态
    isDelete = models.BooleanField(default = False)



# 商品模型
class Goods(models.Model):
    # 名称
    title = models.CharField(max_length=32)
    # 类型
    cateid = models.ForeignKey(to='Cates')
    # 价钱
    price = models.FloatField()
    # 库存
    store = models.IntegerField()
    # 详情
    info = models.TextField()
    # 主图
    pic_url = models.CharField(max_length=100)
    # 0新品 1热卖 2 下架
    status = models.IntegerField(default=0)
    # 点击量
    clicknum = models.IntegerField(default=0)
    # 销量
    ordernum = models.IntegerField(default=0)
    # 发布时间
    addtime = models.DateTimeField(auto_now_add=True)



# 购物车
class Cart(models.Model):
    #uid  gid  num
    # 用户
    uid = models.ForeignKey(to="Users")
    # 商品
    goodsid = models.ForeignKey(to="Goods")
    # 数量
    num = models.IntegerField()



# 城市模型
class Citys(models.Model):
    # 名称
    name = models.CharField(max_length=50)
    # 级别
    level = models.IntegerField()
    # 父级
    upid = models.IntegerField()



# 收货地址模型
class Address(models.Model):
    # 用户
    uid = models.ForeignKey(to = 'Users')
    # 收货人
    shr = models.CharField(max_length=50)
    # 电话
    shdh = models.CharField(max_length=11)
    # 省
    sheng = models.IntegerField()
    # 市
    shi = models.IntegerField()
    # 县
    xian = models.IntegerField()
    # 详址
    info = models.CharField(max_length=100)
    # 状态 0正常 1默认收货 2 过期地址
    isChecked = models.IntegerField(default=0)



# 订单
class Order(models.Model):
    # 用户
    uid = models.ForeignKey(to='Users')
    # 收货人
    shr = models.CharField(max_length=10)
    # 收货电话
    shdh = models.CharField(max_length=11)
    # 地址
    shdz = models.CharField(max_length=100)
    # 支付类型
    buytype = models.CharField(max_length=10) 
    # 物流
    wl = models.CharField(max_length=10)
    # 总价
    totalprice = models.FloatField()
    # 生成时间
    addtime = models.DateTimeField(auto_now_add=True)
    # 支付时间
    buytime = models.DateTimeField(null=True)
    # 状态
    status = models.IntegerField(default=0)



# 订单详细
class OrderInfo(models.Model):
    # 订单号
    orderid = models.ForeignKey(to="Order")
    # 商品号
    goodsid = models.IntegerField()
    # 名称    
    title = models.CharField(max_length=32)
    # 价格
    price = models.FloatField()
    # 数量
    num = models.IntegerField()
    # 主图
    pic_url = models.CharField(max_length=100)


